#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e6 + 10, INF = 0x3f3f3f3f;

ll n, q;
set<ll> s;
struct DSU {
    std::vector<ll> f, sz;
    DSU() {}
    DSU(ll n) { init(n); }
    void init(ll n) {
        n++;
        f.resize(n);
        std::iota(f.begin(), f.end(), 0);
        sz.assign(n, 1);
    }
    ll find(ll x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    ll size(ll x) {
        return sz[find(x)];
    }
    bool merge(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        sz[x] += sz[y];
        f[y] = x;
        return true;
    }
    bool same(ll x, ll y) {
        return find(x) == find(y);
    }
};

void solve()
{
    cin >> n >> q;
    for (ll i = 1;i <= n;i++) s.insert(i);
    DSU dsu(n);
    while (q--) {
        ll x, y;cin >> x >> y;
        ll res = 0;
        for (ll it : s) {
            if (it > x) break;
            res += dsu.size(it);
            dsu.merge(it, y);
        }
        for (auto it = s.begin();it != s.end() && (*it) <= x;it = s.erase(it));
        cout << res << '\n';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}